package com.cjh.mybatis12.executor.result;

import com.cjh.mybatis12.reflection.factory.ObjectFactory;
import com.cjh.mybatis12.session.ResultContext;
import com.cjh.mybatis12.session.ResultHandler;

import java.util.List;

/**
 * @Descripton 默认结果处理器
 * @Author cjh
 * @Date 2023/6/30 10:45
 */
public class DefaultResultHandler implements ResultHandler {

    private final List<Object> list;

    public DefaultResultHandler(List<Object> list) {
        this.list = list;
    }

    public DefaultResultHandler(ObjectFactory objectFactory){
        this.list = objectFactory.create(List.class);
    }

    @Override
    public void handleResult(ResultContext context) {
        list.add(context.getResultObject());
    }

    public List<Object> getResultList(){
        return list;
    }
}
